package com.salton123.soulove.ease.provider

import android.content.Context
import com.hyphenate.easeim.common.repositories.EMClientRepository
import com.salton123.coroutine.Ret
import com.salton123.coroutine.RetDef
import com.salton123.soulove.api.IEaseProvider
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume

/**
 * Time:2022/7/17 22:16
 * Author:
 * Description:
 */
class EaseProvider : IEaseProvider {
    private val emClientRepository: EMClientRepository = EMClientRepository()
    override suspend fun autoLogin(): RetDef {
        return suspendCancellableCoroutine { continuation ->
            emClientRepository.loadAllInfoFromHX().observeForever {
                if (it.data) {
                    continuation.resume(Ret.Success(Unit))
                } else {
                    continuation.resume(Ret.Failure(it.errorCode, it.message))
                }
            }
        }
    }


    override fun init(context: Context?) {
    }
}